define(["dojo/_base/declare", "dijit/form/Form", "dijit/form/TextBox", "dijit/form/NumberTextBox", "dijit/form/Button", "dijit/form/FilteringSelect", "dojo/data/ItemFileReadStore"], function(declare){
    declare("my.form.InnerTransferForm", [dijit.form.Form], {

    	confirmation : false,
    	
    	startup : function() {
    		var accountDropDown = dijit.byId("innerUserAccountDropDown");
    		dijit.byId("innerTransferDropDown").attr("disabled", true); 
    		console.log(accountDropDown);
			dojo.connect(accountDropDown, "onChange", this, function(){
				dojo.xhrPost(
    					{
    						url : "getRachAction.action?rach.id="+dijit.byId('innerUserAccountDropDown').get('value'),
    						handleAs : "json",
    						load : dojo.hitch(this, this.setAvailable),
    					});
			});
    	},
    	
    	setAvailable : function(responseObject, ioArgs){
    		dijit.byId('innerAvailableResources').setValue(responseObject.rach.amount);
    		
    		var transferDropDown = dijit.byId("innerTransferDropDown");
    		console.log(transferDropDown);
    		var store = new dojo.data.ItemFileWriteStore(
		    	    {
		    	    	url:'getMineRachsToTransferToAction.action?rach.id='+dijit.byId('innerUserAccountDropDown').get('value'),
		 			    requestMethod : "post"
		    	    });
    		transferDropDown.set('store', store);
    		transferDropDown.attr("disabled", false); 
    		transferDropDown.reset();
    	},
    	
    	setConfirmation : function(responseObject, ioArgs){
    		this.confirmation = responseObject.conf;
    		console.log(this.confirmation);
    	},
    	
    	onSubmit : function(){
    		var grt = dijit.byId("innerTransferResources").get('value') > 0;
    		var less = dijit.byId("innerTransferResources").get('value') <= dijit.byId('innerAvailableResources').get('value');

    		dojo.xhrPost(
					{
						url : "getConfirmationAction.action?conf="+dijit.byId('innerConfirmationCode').get('value'),
						handleAs : "json",
						sync : true,
						load : dojo.hitch(this, this.setConfirmation),
					});
    		
			return this.isValid() && grt && less && this.confirmation;
		}
    	
    });
});